/*
 * @Author: your name
 * @Date: 2020-08-24 17:27:06
 * @LastEditTime: 2020-08-24 21:02:36
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \新建文件夹\two-app\src\store\addQuestions\index.js
 */
import { getExamType, getQuestionsType, getSubject, addQuestions } from '../../api/addQuestions'
import { Message } from 'view-design'
const state = {
  ExamType: [], // 考试类型
  Subject: [], // 课程类型
  QuestionsType: [] // 题目类型
}

const mutations = {
  setExamType(state, action) {
    state.ExamType = action
  },
  setSubject(state, action) {
    state.Subject = action
  },
  setQuestionsType(state, action) {
    state.QuestionsType = action
  }
}

const actions = {
  // 获取所有类型
  async setAll({ commit }) {
    const data = await getExamType()
    commit('setExamType', data.data.data)
    const data1 = await getSubject()
    commit('setSubject', data1.data.data)
    const data2 = await getQuestionsType()
    commit('setQuestionsType', data2.data.data)
  },
  // 添加试题
  async addQ({ commit }, action) {
    console.log(action, '------参数')
    const data = await addQuestions(action)
    console.log(data)
    if (data.data.code !== 1) {
      return Message.error('添加失败')
    }
    Message.success(data.data.msg)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
